/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import i18n from '@/module/i18n'
import config from '~/external/config'
import Permissions from '@/module/permissions'

const menu = {
  projects: [
    {
      name: '项目管理',
      id: 0,
      path: '',
      isOpen: true,
      enabled: Permissions.getAuth(['scheduling:center:create', 'projects:index']),
      icon: 'icon-a-Yarnduilieguanli',
      children: [
        {
          name: '项目概览',
          path: 'projects-manage-index',
          id: 0,
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:index']),
        },
        {
          name: '项目级别参数',
          path: 'projects-manage-parameter',
          id: 1,
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:index']),
        },
        {
          name: '项目偏好管理',
          path: 'projects-manage-preferences',
          id: 2,
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:index']),
        },
      ]
    },
    {
      name: '工作流管理',
      id: 1,
      path: '',
      isOpen: true,
      enabled: Permissions.getAuth(['scheduling:center:create', 'projects:kinship']),
      icon: 'icon-a-Yarnduilieguanli',
      children: [
        {
          name: '工作流关系',
          id: 1,
          path: 'projects-workflow-kinship',
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:kinship']),
        },
        {
          name: '工作流定义',
          id: 2,
          path: 'projects-workflow-definition',
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:kinship']),
        },
        {
          name: '工作流实例',
          path: 'projects-workflow-instance',
          id: 3,
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:instance:list'])
        },
      ]
    },
    {
      name: '节点管理',
      id: 2,
      path: '',
      isOpen: true,
      enabled: Permissions.getAuth(['scheduling:center:create', 'projects:module']),
      icon: 'icon-a-Yarnduilieguanli',
      children: [
        // {
        //   name: `${i18n.$t('Process definition')}`,
        //   path: 'definition',
        //   id: 0,
        //   enabled: Permissions.getAuth(['scheduling:center:create', 'projects:definition:list']),
        // },
        // {
        //   name: `${i18n.$t('Process Instance')}`,
        //   path: 'instance',
        //   id: 1,
        //   enabled: Permissions.getAuth(['scheduling:center:create', 'projects:instance:list'])
        // },
        {
          name: '节点任务定义',
          path: 'projects-node-task-definition',
          id: 1,
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:task:instance'])
        },
        {
          name: '节点任务实例',
          path: 'projects-node-task-instance',
          id: 2,
          enabled: Permissions.getAuth(['scheduling:center:create', 'projects:task:instance'])
        },
        {
          name: `${i18n.$t('Task record')}`,
          path: 'projects-node-task-record',
          id: 3,
          enabled: config.recordSwitch
        },
        {
          name: `${i18n.$t('History task record')}`,
          path: 'projects-node-history-task-record',
          id: 4,
          enabled: config.recordSwitch
        }
      ]
    }
  ],

  security: [

    {
      name: `${i18n.$t('Worker group manage')}`,
      id: 4,
      path: 'worker-groups-manage',
      isOpen: true,
      enabled: Permissions.getAuth('config:worker-group:list'),
      icon: 'icon-workfenzu',
      children: []
    },
    {
      name: `${i18n.$t('Environment manage')}`,
      id: 3,
      path: 'environment-manage',
      isOpen: true,
      enabled: Permissions.getAuth('config:environment:list'),
      icon: 'icon-huanjingguanli',
      children: []
    },
    {
      name: `${i18n.$t('Token manage')}`,
      id: 2,
      path: 'token-manage',
      isOpen: true,
      icon: 'icon-lingpaiguanli',
      children: [],
      enabled: Permissions.getAuth('config:token:list')
    }
  ],
  system: [
    {
      name: `${i18n.$t('Tenant Manage')}`,
      id: 0,
      path: 'tenement-manage',
      isOpen: true,
      enabled: Permissions.getAuth('system:tenant:list'),
      icon: 'icon-zuhuguanli',
      children: [],
      permission: 'system:tenant:list'
    },
    {
      name: '角色权限',
      id: 1,
      path: 'role-permission',
      isOpen: true,
      enabled: Permissions.getAuth('system:role_permission:list') || true,
      icon: 'icon-jiaoseguanli',
      children: []
    },
    {
      name: `${i18n.$t('User Manage')}`,
      id: 1,
      path: 'users-manage',
      isOpen: true,
      enabled: Permissions.getAuth('system:users:list'),
      icon: 'icon-yonghuguanli',
      children: []
    },
    {
      name: `${i18n.$t('Queue manage')}`,
      id: 3,
      path: 'queue-manage',
      isOpen: true,
      enabled: Permissions.getAuth('system:queue:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: `${i18n.$t('Warning group manage')}`,
      id: 2,
      path: 'warning-groups-manage',
      isOpen: true,
      enabled: Permissions.getAuth('system:warning-group:list'),
      icon: 'icon-gaojingzuguanli',
      children: []
    },
    {
      name: `${i18n.$t('Warning instance manage')}`,
      id: 2,
      path: 'warning-instance-manage',
      isOpen: true,
      enabled: Permissions.getAuth('system:warning-instance:list'),
      icon: 'icon-gaojingshiliguanli',
      children: []
    }

  ],
  resource: [
    {
      name: `${i18n.$t('File Manage')}`,
      id: 0,
      path: 'file',
      isOpen: true,
      icon: 'icon-a-Yarnduilieguanli',
      children: [],
      enabled: Permissions.getAuth('resource:file:list')
    },
    {
      name: `${i18n.$t('UDF manage')}`,
      id: 1,
      path: '',
      isOpen: true,
      icon: 'icon-a-Yarnduilieguanli',
      enabled: Permissions.getAuth(['resource:udf:list', 'resource:resource:list', 'resource:func:list']),
      children: [
        {
          name: `${i18n.$t('Resource manage')}`,
          path: 'resource-udf',
          id: 0,
          enabled: Permissions.getAuth('resource:resource:list')
        },
        {
          name: `${i18n.$t('Function manage')}`,
          path: 'resource-func',
          id: 1,
          enabled: Permissions.getAuth('resource:func:list')
        }
      ]
    },
    {
      name: `${i18n.$t('Datasource manage')}`,
      id: 2,
      path: 'datasource',
      isOpen: true,
      icon: 'icon-a-Yarnduilieguanli',
      children: [],
      enabled: Permissions.getAuth('resource:datasource:list')
    }
  ],
  user: [
    {
      name: `${i18n.$t('User Information')}`,
      id: 0,
      path: 'account',
      isOpen: true,
      icon: 'icon-a-Yarnduilieguanli',
      children: [],
      enabled: true
    },
    {
      name: `${i18n.$t('Edit password')}`,
      id: 1,
      path: 'password',
      isOpen: true,
      icon: 'icon-a-Yarnduilieguanli',
      children: [],
      enabled: true
    },
    {
      name: `${i18n.$t('Token manage')}`,
      id: 2,
      path: 'token',
      isOpen: true,
      icon: 'icon-a-Yarnduilieguanli',
      children: [],
      enabled: Permissions.getAuth()
    }
  ],
  monitor: [
    {
      name: `${i18n.$t('Servers manage')}`,
      id: 1,
      path: '',
      isOpen: true,
      enabled: Permissions.getAuth(['monitor:service:list', 'monitor:service:worker:list', 'monitor:service:master:list', 'monitor::DB:list']),
      icon: 'icon-a-Yarnduilieguanli',
      children: [
        {
          name: 'Master',
          path: 'servers-master',
          id: 0,
          enabled: Permissions.getAuth('monitor:service:master:list')
        },
        {
          name: 'Worker',
          path: 'servers-worker',
          id: 1,
          enabled: Permissions.getAuth('monitor:service:worker:list')
        },
        {
          name: 'DB',
          path: 'servers-db',
          id: 6,
          enabled: Permissions.getAuth('monitor::DB:list')
        }
      ]
    },
    {
      name: `${i18n.$t('Statistics manage')}`,
      id: 0,
      path: '',
      isOpen: true,
      enabled: Permissions.getAuth(['monitor:statistic:list', 'monitor:statistic:task:list']),
      icon: 'icon-a-Yarnduilieguanli',
      children: [
        {
          name: '任务统计',
          path: 'statistics',
          id: 0,
          enabled: Permissions.getAuth('monitor:statistic:task:list')
        }
      ]
    }
  ],
  equipment: [
    {
      name: '机主申请',
      id: 0,
      path: 'equipment-application',
      isOpen: true,
      enabled: Permissions.getAuth('equipment:network:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '算力路由',
      id: 1,
      path: 'equipment-route',
      isOpen: true,
      enabled: Permissions.getAuth('equipment:route:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '虚拟网络',
      id: 2,
      path: 'equipment-network',
      isOpen: true,
      enabled: Permissions.getAuth('equipment:network:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },

  ],
  operation: [
    // {
    //   name: '统计概览',
    //   id: 0,
    //   path: 'operation-_source',
    //   isOpen: true,
    //   enabled: Permissions.getAuth('operation:overview:list'),
    //   icon: 'el-icon-user-solid',
    //   children: []
    // },
    {
      name: '运营概览',
      id: 0,
      path: 'operation-operationalOverview',
      isOpen: true,
      enabled: Permissions.getAuth('operation:overview:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '资源管理',
      id: 1,
      path: 'operation-resourceList',
      isOpen: true,
      enabled: Permissions.getAuth('operation:product:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '订单管理',
      id: 2,
      path: 'operation-orderList',
      isOpen: true,
      enabled: Permissions.getAuth('operation:order:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '收支明细',
      id: 3,
      path: 'operation-incomeDetail',
      isOpen: true,
      enabled: Permissions.getAuth('operation:bill:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '运营配置',
      id: 4,
      path: 'operation-operationConfiguration',
      isOpen: true,
      enabled: Permissions.getAuth('operation:chargingrule:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    }
  ],
  scheduler: [
    {
      name: '调度中心',
      id: 0,
      path: 'scheduler-overview',
      isOpen: true,
      enabled: Permissions.getAuth('scheduling:center:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    },
    {
      name: '资源列表',
      id: 1,
      path: 'scheduler-resource',
      isOpen: true,
      enabled: Permissions.getAuth('scheduling:resource:list'),
      icon: 'icon-a-Yarnduilieguanli',
      children: []
    }

  ]
}

export default type => menu[type]
